﻿Chenxin.UI.ServiceOver = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/ShowListServiceOver.ashx',
    createGrid: function() {
        var _this = this;
        return new Chenxin.UI.MultiRowGrid({
            actionUrl: this.actionUrl + '?op=getlist',
            pageSize: 50,
            height: 400,
            renderTo: 'divShowLsSvrOver',
            hasCheckBox: false,
            title: '对比分析表',
            id: 'overlist',
            scope: this,
            autoLoad: false,
            modelId: 'ContractId',
            columns: {
                HasOver: {
                    width: 60,
                    head: '状态',
                    renderer: function(val, field, row) {
                        if (val)
                            return '已核销';
                        else
                            return '未核销';
                    }
                },
                ContractCode: {
                    width: 120,
                    head: '成交编号'
                },
                ContractDate: {
                    width: 120,
                    head: '成交日期'
                },
                HouseAddress: {
                    width: 250,
                    head: '房源地址'
                },
                Departs: {
                    width: 200,
                    head: '门店'
                },
                RealCommisionFinal: {
                    width: 80,
                    items: {
                        VRealCommisionFinal: {
                            width: 80,
                            head: '上家确认佣收'
                        },
                        BRealCommisionFinal: {
                            width: 80,
                            head: '下家确认佣收'
                        }
                    }
                },
                CommisionGeted: {
                    width: 80,
                    items: {
                        VCommisionGeted: {
                            width: 80,
                            head: '上家实收'
                        },
                        BCommisionGeted: {
                            width: 80,
                            head: '下家实收'
                        }
                    }
                },
                fwf_count: {
                    width: 120,
                    head: '服务费收据编号',
                    renderer: function(val, field, row) {
                        return '<a href="javascript:void(0)" class="fwfshow" contractid=' + row.ContractId + '>' + val + '</a>';
                    }
                },
                servicemoney: {
                    width: 120,
                    items: {
                        vservicemoney: {
                            width: 120,
                            head: '上家服务费收据金额'
                        },
                        bservicemoney: {
                            width: 120,
                            head: '下家服务费收据金额'
                        }
                    }
                },
                billmoney: {
                    width: 120,
                    items: {
                        vbillmoney: {
                            width: 120,
                            head: '上家开单佣金金额'
                        },
                        bbillmoney: {
                            width: 120,
                            head: '下家开单佣金金额'
                        }
                    }
                },
                bill_count: {
                    width: 100,
                    head: '佣金开单编号',
                    renderer: function(val, field, row) {
                        return '<a href="javascript:void(0)" class="billshow" contractid=' + row.ContractId + '>' + val + '</a>';
                    }
                },
                OverName: {
                    width: 80,
                    head: '核销确认人'
                },
                OverTime: {
                    width: 80,
                    head: '核销时间'
                }
            }
        })
    },
    initEvent: function() {
        var _this = this;
        //导出Excel
        $('#aExportExcel').click(function() {
            _this.exportData();
        });
        //底部按钮点击事件
        $('.LeftFooter a').click(function() {
            _this.bindBottomBar(this);
        });
        $('.fwfshow').live('click', function() {
            _this.showFWF('getfwf', $(this).attr('contractid'));
        });
        $('.billshow').live('click', function() {
            _this.showBill('getbill', $(this).attr('contractid'));
        });
    },
    showFWF: function(op, contractid) {
        if (!this.detailsWin_fwf) {
            this.detailsWin_fwf = new Chenxin.UI.DetailsWin_fwf({
                id: 'x_details_fwf',
                actionUrl: this.actionUrl
            });
        }
        this.detailsWin_fwf.show();

        this.detailsWin_fwf.setTitle('服务费收据明细');
        this.detailsWin_fwf.grid.baseParam.op = op;
        this.detailsWin_fwf.grid.param.contractid = contractid;
        this.detailsWin_fwf.grid.reload();
    },
    showBill: function(op, contractid) {
        if (!this.detailsWin) {
            this.detailsWin = new Chenxin.UI.DetailsWin({
                id: 'x_details_bill',
                actionUrl: this.actionUrl
            });
        }
        this.detailsWin.show();

        this.detailsWin.setTitle('佣金开单明细');
        this.detailsWin.grid.baseParam.op = op;
        this.detailsWin.grid.param.contractid = contractid;
        this.detailsWin.grid.reload();
    },
    bindBottomBar: function(obj) {
        switch (obj.name) {
            case "over":
                if (!this.currentId) {
                    alert("请选择一条记录进行操作！");
                    return false;
                }
                if (this.grid.getCurrentRecord().HasOver == "1") {
                    alert("此合同已核销，不可执行核销操作！");
                    return false;
                };
                this.del('over', '是否核销？');
                break;
            case "unover":
                if (!this.currentId) {
                    alert("请选择一条记录进行操作！");
                    return false;
                }
                if (this.grid.getCurrentRecord().HasOver != "1") {
                    alert("此合同未核销，不可执行反核销操作！");
                    return false;
                };
                this.del('unover', '是否反核销？');
                break;
            default:
                alert("功能未开通");
        }
    },
    createSearch: function() {
        return new Chenxin.UI.ServiceOverSearch({
            scope: this
        });
    }
});

/**
*查询面板
*/
Chenxin.UI.ServiceOverSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'divCondition',
    initEvent: function() {
        var _this = this;
        //查询
        $('#btnSearch').click(function() {
            var data = _this.scope.search.getParamJson();
            _this.scope.reloadGrid(data);
        });

        $('#txtKeyword').defText({
            deftxt: '请输入地址或成交编号'
        });
    },
    createComboList: function() {
        //合同类型
        var status = new Chenxin.UI.Combo({
            containerId: '#status',
            tbxWidth: 65,
            items: comboCommon.OverStatus,
            addPleaseSelected:false
        });
        return [status];
    }
});

//服务费明细层
Chenxin.UI.DetailsWin_fwf = Chenxin.extend(Chenxin.UI.Win, {
    id: '',
    actionUrl: '',
    width: 680,
    hasFoot: true,
    height: 360,
    content: '<div id="x_details_win"></div>',
    createBtn: function() {
        return [{
            text: '关闭',
            handler: this.hide
}]
        },
        createGrid: function() {
            if (this.grid) {
                return;
            }
            this.grid = new Chenxin.UI.JsonGrid({
                baseParam: { op: '' },
                autoLoad: false,
                actionUrl: this.actionUrl,
                id: 'x_details_fwf',
                renderTo: 'x_details_win',
                hasCheckBox: false,
                cellBorder: true,
                modelId: 'a',
                scope: this,
                height: 311,
                hasTitle: false,
                columns: {
                    //ContractCode: { head: '合同编号', width: 150 },
                    //Address: { head: '房源地址', width: 200 },
                    ReceiptCode: { head: '服务费编号', width: 150 },
                    ReceiptMoneyName: { head: '收款类型', width: 100 },
                    GetedMoney: { head: '金额', width: 80 },
                    GetedTime: { head: '收取时间', width: 100 }
                }
            });
        },
        initComponent: function() {
            Chenxin.UI.DetailsWin_fwf.superclass.initComponent.call(this);
            this.createGrid();
        }
    });

    //开单明细层
    Chenxin.UI.DetailsWin = Chenxin.extend(Chenxin.UI.Win, {
        id: '',
        actionUrl: '',
        width: 680,
        hasFoot: true,
        height: 360,
        content: '<div id="x_details_win1"></div>',
        createBtn: function() {
            return [{
                text: '关闭',
                handler: this.hide
}]
            },
            createGrid: function() {
                if (this.grid) {
                    return;
                }
                this.grid = new Chenxin.UI.JsonGrid({
                    baseParam: { op: '' },
                    autoLoad: false,
                    actionUrl: this.actionUrl,
                    id: 'x_details_bill',
                    renderTo: 'x_details_win1',
                    hasCheckBox: false,
                    cellBorder: true,
                    modelId: 'b',
                    scope: this,
                    height: 311,
                    hasTitle: false,
                    columns: {
                        //ContractCode: { head: '合同编号', width: 150},
                        BillCode: { head: '单据编号', width: 150 },
                        FundName: { head: '款项名称', width: 100 },
                        BillMoney: { head: '开单金额', width: 80 },
                        BillDate: { head: '开单时间', width: 80 },
                        PayMoney: { head: '已收金额', width: 100 },
                        PayDate: { head: '收款时间', width: 100 }
                    }
                });
            },
            initComponent: function() {
                Chenxin.UI.DetailsWin.superclass.initComponent.call(this);
                this.createGrid();
            }
        });


$(document).ready(function() {
    this.ServiceOver = new Chenxin.UI.ServiceOver();
});